import java.io.File
import java.util

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

/**
 *
 * @author tzp
 * @since 2019/7/31
 */
object CollectTest extends App {
  println("Hello, World!")

  {
    var mp = new mutable.TreeMap[String, Int]()
    val a = ("a", 1)
    var ne = mp + a
    println(" " + ne)

    mp += ("b" -> 2)
    println(" " + mp)
  }

  {
    var mp = mutable.Map("a" -> 1)
    mp.+=("b" -> 2)
  }

  {
    var x = new util.TreeMap[String, Int]()
    x.put("a", 2)
    x.put("b", 3)
    x.put("c", 4)
    x.put("d", 3)
    x.put("e", 2)
    x.remove(x.firstKey())
    println(x)
  }

  {
    var x = new ArrayBuffer[(Int, Int)](Math.pow(10, 1).toInt)
    x += ((1, 3)) //为啥特么俩括号
    x += ((2, 4)) //https://stackoverflow.com/questions/37810347/append-listbuffer-with-tuple
    println(x)
  }
  {
    val c: Char = 97.asInstanceOf[Char]
    "hello".asInstanceOf[String]
    1.asInstanceOf[Long]
    val it: Seq[String] = List("a", "b")
    it.asInstanceOf[List[String]]

    "hello".isInstanceOf[String]

    classOf[String]
  }

  {
    var x = Map[Int, Int]()
    x += (1 -> 2)
    x += ((1, 2)) //需要两层括号
    x = x + ((1, 2))
    x = x.+((1, 2))
    x = x.+(1 -> 2)

    val b = for (xx <- x) {
      println(xx)
    }

    println(b) //b是Unit, 打印()
  }

  def echo(args: String*) = for (arg <- args) println(arg) //内部看到的args是Array[String], 但是调用函数如果传Array会报错

  echo("x", "o")
  val ar = Array("xx", "bb")
  //  echo(ar)//编译错误
  echo(ar: _*)

  def sum(a: Int, b: Int, c: Int): Int = a + b + c

  val a = sum _
  println(a(1, 2, 3))
  val x = List(1,2,3)
  def xx(f: Int => Int) {
    f(1)
  }
}